package com.carrot.newsgallery.common;

import com.carrot.newsgallery.utils.ReturnCode;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;

@Data
public class R {

    private int code; //编码：0成功，其它数字为失败

    private String msg; //错误信息

    private Object data; //数据

    private Map map = new HashMap(); //动态数据

    public static R success(Object object, String msg) {
        R r = new R();
        r.data = object;
        r.msg = msg;
        r.code = 0;
        return r;
    }

    public static R fail(ReturnCode rc, String msg){
        R r = new R();
        r.msg = msg;
        r.code = rc.getValue();
        return r;
    }

    public R add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

}
